package com.ysy.tz.core.selfcomp;

import com.ysy.tz.core.skin.CustomerTableViewSkin;
import com.ysy.tz.core.utils.FileResourceLoader;
import java.io.IOException;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.Skin;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

public class CusomterTableView extends TableView {
    public CusomterTableView() {
        try {
            this.getStylesheets().add(FileResourceLoader.loadURL("/views/css/customerTableView.css").toString());
        } catch (IOException var2) {
            var2.printStackTrace();
        }

    }

    protected Skin<?> createDefaultSkin() {
        Skin skin = new CustomerTableViewSkin(this);
        this.getColumns().forEach((tableColumn) -> {
            if (tableColumn instanceof DateTableColumn) {
                ((DateTableColumn)tableColumn).setCellValueFactory(new PropertyValueFactory(((DateTableColumn)tableColumn).getId().substring(3)));
            } else if (!(tableColumn instanceof NodeTableColumn)) {
                TableColumn tc = (TableColumn)tableColumn;
                if (tc.getId().equals("tableSeqNo")) {
                    tc.setCellFactory((col) -> {
                        TableCell<Alert, String> cell = new TableCell<Alert, String>() {
                            public void updateItem(String item, boolean empty) {
                                super.updateItem(item, empty);
                                this.setText((String)null);
                                this.setGraphic((Node)null);
                                if (!empty) {
                                    int rowIndex = this.getIndex() + 1;
                                    this.setText(String.valueOf(rowIndex));
                                }

                            }
                        };
                        return cell;
                    });
                }

                if (tc.getCellValueFactory() == null && !(tc instanceof NodeTableColumn)) {
                    tc.setCellValueFactory(new PropertyValueFactory(tc.getId().substring(3)));
                }
            }

        });
        return skin;
    }
}
